const {exec} = require('child_process');
const iconv = require('iconv-lite');

let cmd = 'wmic process where name="ffmpeg.exe" get CommandLine,ProcessId';

exec(cmd, {encoding: 'utf-8'}, (error, stdout) => {
    let list = stdout.split("\n");
    for (let i = 0; i < list.length; i++) {
        let line = list[i].trim();
        if (line == "CommandLine" || line.indexOf("ffmpeg.exe") < 0) {
            continue;
        }

        console.log("==================")
        // console.log(line)

        var reg = /-metadata pid=(\S+)/;
        let result = reg.exec(line);
        if (result && result.length > 1) {
            let id = result[1];
            console.log(id)
        }

        reg = /\s+(\d+)$/;
        result = reg.exec(line);
        if (result && result.length > 1) {
            let pid = result[1];
            console.log(pid.trim())
        }

    }
});